import { TablePropType } from '@/interfaces/Element/Table'
import { tableData, TableDataObjType, tableType } from './tableType'
interface PageType {
  currentPage: number
  pageSize: number
}
export const page = reactive<PageType>({
  currentPage: 1,
  pageSize: 10
})
export const data = computed(() => {
  const result = tableData.value.slice(
    (page.currentPage - 1) * page.pageSize,
    page.currentPage * page.pageSize
  )
  return result
})

export const handleEdit = (row: TableDataObjType) => {
  let getHtml = ''
  for (const key in row) {
    getHtml += `<div>${key}: ${row[key]};</div>`
  }
  ElNotification({
    title: 'Success',
    dangerouslyUseHTMLString: true,
    message: getHtml,
    type: 'success'
  })
}
export const handleDelete = (row: TableDataObjType) => {
  const findIndex = tableData.value.findIndex((item: TableDataObjType) => item.id === row.id)
  tableData.value.splice(findIndex, 1)
}
export const getNewDataType = (
  data: Array<TablePropType> | Array<TableDataObjType>,
  drag: string
) => {
  switch (drag) {
    case 'column':
      tableType.value = data as Array<TablePropType>
      return
    case 'row':
      tableData.value = data as Array<TableDataObjType>
      return
    default:
      break
  }
}
